<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="f1202">
        <el-input v-model="queryParams.f1202" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="反馈状态" prop="f1205">
        <el-select v-model="queryParams.f1205" clearable @keyup.enter.native="handleQuery" placeholder="请选择反馈状态">
          <el-option label="已回复" :value="0"></el-option>
          <el-option label="未回复" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="公司名称" prop="f1208">
        <el-input v-model="queryParams.f1208" placeholder="请输入公司名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
          @click="handleDelete">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="T12List" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="f1202" />
      <el-table-column label="反馈内容" align="center" prop="f1203" />
      <el-table-column label="反馈状态" align="center" prop="f1205">
        <template slot-scope="scope">
          <el-tag :type="scope.row.f1205 === 0 ? 'success' : 'danger'">{{ scope.row.f1205 === 0 ? '已回复' :
            '未回复' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="公司名称" align="center" prop="f1208" />
      <el-table-column label="邮箱" align="center" prop="f1209" />
      <el-table-column label="反馈时间" align="center" prop="F1204" width="180" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" v-if="scope.row.f1205 === 1" icon="el-icon-edit" @click="handleUpdate(scope.row)">回复</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改信息反馈对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="姓名" prop="f1202">
          <el-input disabled v-model="form.f1202" />
        </el-form-item>
        <el-form-item label="反馈内容">
          <el-input disabled v-model="form.f1203" type="textarea" />
        </el-form-item>
        <el-form-item label="反馈状态" prop="f1205">
          <el-select disabled style="width: 100%;" v-model="form.f1205" placeholder="请选择反馈状态">
            <el-option label="已回复" :value="0"></el-option>
            <el-option label="未回复" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="反馈时间" prop="f1204">
          <el-date-picker disabled style="width: 100%;" clearable v-model="form.f1204" type="date"
            value-format="yyyy-MM-dd" placeholder="请选择反馈时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="回复内容">
          <el-input v-model="form.f1207" type="textarea" placeholder="请输入回复内容" />
        </el-form-item>
        <el-form-item label="公司名称" prop="f1208">
          <el-input disabled v-model="form.f1208" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="邮箱" prop="f1209">
          <el-input disabled v-model="form.f1209" placeholder="请输入邮箱" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listT12, getT12, delT12, addT12, updateT12 } from "@/api/system/T12";

export default {
  name: "T12",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 信息反馈表格数据
      T12List: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        f0601: null,
        f1202: null,
        f1203: null,
        f1204: null,
        f1205: 1,
        f0101: null,
        f0301: null,
        f1206: null,
        f1207: null,
        f1208: null,
        f1209: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        f1207: { required: true, message: "回复内容不能为空", trigger: "blur" },
      },
      names: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询信息反馈列表 */
    getList() {
      this.loading = true;
      listT12(this.queryParams).then(response => {
        this.T12List = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        f1201: null,
        f0601: null,
        f1202: null,
        f1203: null,
        f1204: null,
        f1205: null,
        f0101: null,
        f0301: null,
        f1206: null,
        f1207: null,
        f1208: null,
        f1209: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.f1201)
      this.names = selection.map(item => item.f1202)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加信息反馈";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const F1201 = row.f1201 || this.ids
      getT12(F1201).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改信息反馈";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.f1201 != null) {
            updateT12(this.form).then(response => {
              this.$modal.msgSuccess("回复成功");
              this.open = false;
              this.getList();
            });
          } else {
            addT12(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const names = row.f1202 || this.names;
      const F1201s = row.f1201 || this.ids;
      this.$modal.confirm('是否确认删除信息反馈姓名为"' + names + '"的数据项？').then(function() {
        return delT12(F1201s);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/T12/export', {
        ...this.queryParams
      }, `T12_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
